
//
//  SHCashUnionPayCell.m
//  JiFengDaRen
//
//  Created by SH_iOS on 2018/1/11.
//  Copyright © 2018年 SH_iOS. All rights reserved.
//
#import "UIButton+EnlargeTouchArea.h"
#import "SHUnionPayModel.h"
#import "SHCashUnionPayCell.h"
@interface SHCashUnionPayCell()
@property(nonatomic,strong)SHLabel *unionPayRateLable;//费率
@property(nonatomic,strong)SHButton *statuBtn;//状态
@property(nonatomic,strong)SHButton *redRateBtn;//手续费红色View
@property(nonatomic,strong)UIImageView *arrowImgView;
@property(nonatomic,strong)UIView *lineView;


@end
@implementation SHCashUnionPayCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;

        _unionPayRateLable  = [SHLabel labelWithTextFont:15 textColor:KSHTEXTCOLOR textAlignment:NSTextAlignmentLeft];
        _unionPayRateLable.text = @"";
        [self.contentView addSubview:_unionPayRateLable];
        [_unionPayRateLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView.mas_left).with.offset(__I6Width(15));
           make.centerY.mas_equalTo(self.contentView.mas_centerY);
            
        }];
        
        _redRateBtn  = [SHButton buttonWithType:UIButtonTypeCustom] ;
        
        _redRateBtn.backgroundColor = KREDCOLOR;
        _redRateBtn.layer.cornerRadius = __I6Width(15)/2;
        _redRateBtn.layer.masksToBounds = YES;
        [_redRateBtn setEnlargeEdgeWithTop:15 right:50 bottom:40 left:100];
        [_redRateBtn setTitle:@"手续费" font:11 titleColor:[UIColor whiteColor] textAlignment:(UIControlContentHorizontalAlignmentCenter) forState:UIControlStateNormal] ;
        [_redRateBtn addTarget:self action:@selector(redRateBtnAction:) forControlEvents:(UIControlEventTouchUpInside)];
        [self.contentView addSubview:_redRateBtn];
        [_redRateBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self->_unionPayRateLable.mas_right).with.offset(-2);
            make.bottom.mas_equalTo(self->_unionPayRateLable.mas_top).with.offset(__I6Width(8));
               make.width.mas_equalTo(__I6Width(40));
               make.height.mas_equalTo(__I6Width(15));

        }];
        
        _statuBtn = [SHButton buttonWithType:UIButtonTypeCustom title:@"确认支付" font:15 titleColor:KREDCOLOR textAlignment:UIControlContentHorizontalAlignmentCenter forState:UIControlStateNormal];
        _statuBtn.userInteractionEnabled = NO;
        [self.contentView addSubview:_statuBtn];
        [_statuBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.contentView.mas_right).with.offset(__I6Width(-38));
            make.centerY.mas_equalTo(self.contentView.mas_centerY);
            
        }];
        
        
        _arrowImgView = [[UIImageView alloc]init];
        _arrowImgView.image = [UIImage imageNamed:@"jmarrow"];
        [self.contentView addSubview:_arrowImgView];
    
        [_arrowImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.right.mas_equalTo(self.contentView.mas_right).mas_offset(__I6Width(-15));
            make.width.mas_equalTo(__I6Height(8));
            make.height.mas_equalTo(__I6Height(14));
        }];
        
        _lineView = [[UIView alloc]init];
        _lineView.backgroundColor = KLINECOLOR;
        [self.contentView addSubview:_lineView];
        
        [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
          make.bottom.mas_equalTo(self.contentView.mas_bottom);
        make.left.mas_equalTo(self.contentView.mas_left).mas_offset(__I6Width(15));
        make.right.mas_equalTo(self.contentView.mas_right).mas_offset(0);

            make.height.mas_equalTo(0.5);
            
        }];
        
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated{
    
    [super setSelected:selected animated:animated];
    if (selected) {
        
        self.layer.backgroundColor = [UIColor colorWithWhite:242/255.0 alpha:1].CGColor;
        
    }else{
        
        self.layer.backgroundColor = [UIColor whiteColor].CGColor;
        
    }
}

- (NSString *)getRateFeeB:(NSString *)rateFee{
    
    float rateFeeFloat  = [rateFee floatValue];
    NSString *rateFeeB = [NSString stringWithFormat:@"%.2f%@",rateFeeFloat*100,@"%"];
    return rateFeeB;
}

-  (void)setUnionPayModel:(SHUnionPayModel *)unionPayModel{
    
    _unionPayModel = unionPayModel;
   
    _unionPayRateLable.text = [NSString stringWithFormat:@"%@ %@",[self getNumber:unionPayModel.index],unionPayModel.Handling_fee];
    //[NSString stringWithFormat:@"%@  %@+%@",[self getNumber:unionPayModel.index],[self getRateFeeB:unionPayModel.trad_fee],unionPayModel.withdraw_rate];
    
    
    if (unionPayModel.status) {//显示确认支付
        
        [self.statuBtn setTitle:unionPayModel.use_title forState:UIControlStateNormal];
        [self.statuBtn setTitleColor:[UIColor colorWithHexString:unionPayModel.use_color] forState:UIControlStateNormal];
        _redRateBtn.hidden = NO;
    }else{
        
        [self.statuBtn setTitle:unionPayModel.use_title forState:UIControlStateNormal];
        [self.statuBtn setTitleColor:[UIColor colorWithHexString:unionPayModel.use_color] forState:UIControlStateNormal];
        _redRateBtn.hidden = YES;


    }
    
    CGFloat rateMsgW = [SHHelper widthOfString:_unionPayModel.red_content font:KSystemFont(14) height:__I6Width(15)];
    [_redRateBtn setTitle:_unionPayModel.red_content forState:(UIControlStateNormal)];
    [_redRateBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self->_unionPayRateLable.mas_right).with.offset(-2);
        make.bottom.mas_equalTo(self->_unionPayRateLable.mas_top).with.offset(__I6Width(8));
        make.width.mas_equalTo(__I6Width(rateMsgW));
        make.height.mas_equalTo(__I6Width(15));
        
    }];
    
    
}

- (NSString *)getNumber:(NSInteger )index{
    
    
    switch (index + 1) {
        case 1:
            return  @"①";
        case 2:
            return  @"②";
        case 3:
            return  @"③";
        case 4:
            return  @"④";
        case 5:
            return  @"⑤";
        case 6:
            return  @"⑥";
        case 7:
            return  @"⑦";
        case 8:
            return  @"⑧";
        case 9:
            return  @"⑨";
            
        case 10:
            return  @"⑩";
        case 11:
            return  @"⑪";
        case 12:
            return  @"⑫";
        case 13:
            return  @"⑬";
        case 14:
            return  @"⑭";
        case 15:
            return  @"⑮";
        case 16:
            return  @"⑯";
        case 17:
            return  @"⑰";
        case 18:
            return  @"⑱";
        case 19:
            return  @"⑲";
        case 20:
            return  @"⑳";
            
        
    }

    return  @"";
    
}
- (void)redRateBtnAction:(UIButton *)sender{
    
   
    if (_delegate && [_delegate respondsToSelector:@selector(cashUnionPayCell: showRateTitle:Msg:)]) {
        
        [_delegate cashUnionPayCell:self showRateTitle:_unionPayModel.red_content Msg:_unionPayModel.instructions];
    }
    
    
}
@end
